package com.wind.taobao.api.picture.convert
{
	import com.wind.taobao.api.picture.model.PictureCategory;
	import com.wind.taobao.core.util.TaobaoConstants;

	import mx.collections.ArrayCollection;


	/**
	 * PictureCategoryConvert转换器
	 * @author fxy
	 *
	 */
	public class PictureCategoryConvert
	{
		/**
		 * 转换PictureCategory集合
		 */
		public static function convertPictureCategorys(value:Object, type:String="json"):ArrayCollection
		{
			var pictureCategorys:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							pictureCategorys.addItem(convertPictureCategory((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return pictureCategorys;
		}

		/**
		 * 转换PictureCategory
		 */
		public static function convertPictureCategory(value:Object, type:String="json"):PictureCategory
		{
			var pictureCategory:PictureCategory=new PictureCategory();
			if (value == null)
				return pictureCategory;
			if (type == TaobaoConstants.XML)
			{
				pictureCategory=convertXMLToPictureCategory(XML(value), pictureCategory);
			}
			else
			{
				pictureCategory=convertJSONToPictureCategory(value, pictureCategory);
			}
			return pictureCategory;
		}

		/**
		 * JSON转换为PictureCategory
		 */
		private static function convertJSONToPictureCategory(json:Object, pictureCategory:PictureCategory):PictureCategory
		{
			if (json.hasOwnProperty(TaobaoConstants.PICTURE_CATEGORY_ID))
			{
				pictureCategory.picture_category_id=json[TaobaoConstants.PICTURE_CATEGORY_ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.PICTURE_CATEGORY_NAME))
			{
				pictureCategory.picture_category_name=json[TaobaoConstants.PICTURE_CATEGORY_NAME];
			}
			if (json.hasOwnProperty(TaobaoConstants.UID))
			{
				pictureCategory.uid=json[TaobaoConstants.UID];
			}
			if (json.hasOwnProperty(TaobaoConstants.SORTS))
			{
				pictureCategory.sorts=json[TaobaoConstants.SORTS];
			}
			if (json.hasOwnProperty(TaobaoConstants.TYPE))
			{
				pictureCategory.type=json[TaobaoConstants.TYPE];
			}
			if (json.hasOwnProperty(TaobaoConstants.TOTAL))
			{
				pictureCategory.total=json[TaobaoConstants.TOTAL];
			}
			if (json.hasOwnProperty(TaobaoConstants.GMT_CREATE))
			{
				pictureCategory.gmt_create=json[TaobaoConstants.GMT_CREATE];
			}
			if (json.hasOwnProperty(TaobaoConstants.GMT_MODIFIED))
			{
				pictureCategory.gmt_modified=json[TaobaoConstants.GMT_MODIFIED];
			}
			return pictureCategory;
		}

		/**
		 * XML转换为PictureCategory
		 */
		private static function convertXMLToPictureCategory(value:XML, pictureCategory:PictureCategory):PictureCategory
		{
			return pictureCategory;
		}
	}
}